= modal_header(intervention.name)

.modal-body{ data: { intervention_id: intervention.id }}

  .indicators
    .med-info.total-cost
      %span.title= :total_cost.tl
      %span.value
        %i.picto.picto-timelapse
        - currency = Nomen::Currency.find(resource.currency)
        = resource.total_cost.round(currency.precision).l(currency: currency.name)

    .med-info
      %span.title= Intervention.human_attribute_name(:working_duration)
      %span.value
        %i.picto.picto-timelapse
        = human_duration(resource.working_duration)

    .med-info
      %span.title= Intervention.human_attribute_name(:started_at)
      %span.value
        %i.picto.picto-clock-o
        = resource.started_at.l(format: :compact)

    .med-info
      %span.title= Intervention.human_attribute_name(:stopped_at)
      %span.value
        %i.picto.picto-clock-o
        = resource.stopped_at.l(format: :compact)

  - if intervention.activities.any?
    .intervention-activities
      - intervention.activities.each do |activity|
        = link_to({ action: :show, controller: :activities, id: activity.id}, style: "background-color: #{activity.color}; color: #{contrasted_color(activity.color)}", class: 'label') do
          = activity.name
  .blocks

    - if intervention.targets.any?
      .block
        %h3.block-title= Intervention.human_attribute_name(:targets)

        - intervention.targets.each do |target|
          - title = target.product.name
          - detail = target.product.nature.name
          - if target.product.has_indicator? :shape
            - detail << ' - ' + target.human_working_zone_area unless target.working_zone_area.nil?
          = add_detail_to_modal_block(title, detail, {icon: 'picto-land-parcels'})

    - if intervention.doers.any?
      .block
        %h3.block-title= Intervention.human_attribute_name(:doers)

        - intervention.doers.each do |doer|
          - title = doer.product.name
          - detail = doer.name
          = add_detail_to_modal_block(title, detail, doer, {icon: 'picto-male'})

    - if intervention.inputs.any?
      .block
        %h3.block-title= Intervention.human_attribute_name(:inputs)

        - intervention.inputs.each do |input|
          - unless input.product.blank?
            - title = input.product.name
            - detail = ""

            - unless input.quantity_value.nil?
              - detail = input.quantity_value.round(2).l(precision: 0)

              - if input.is_population?
                - unit = input.variant.unit_name.mb_chars.downcase
              - else
                - unit = input.quantity_handler_reference.unit.symbol

              - detail << " " + unit

            = add_detail_to_modal_block(title, detail, {icon: 'picto-matter'})
            .registered-phytosanitary-usage-block
              - unless input.usage.nil?
                %p
                  = succeed " : " do
                    %span.title= t(:usage)
                  %span.value= input.usage.ephy_usage_phrase
                  - authorization_calculator = Interventions::Phytosanitary::InterventionInputAuthorizationCalculator.for_intervention(intervention)
                  - vote, messages = authorization_calculator.authorization_state(input)
                  - if vote == :allowed
                    %span.value= :allowed.tl
                  - elsif vote == :forbidden
                    %span.value= :forbidden.tl
                    %span.value= messages.join(', ')

    - if intervention.outputs.any?
      .block
        %h3.block-title= Intervention.human_attribute_name(:outputs)

        - intervention.outputs.each do |output|
          - unless output.product.blank?
            - title = output.product.name
            - detail = ""

            - unless output.quantity_value.nil? || output.quantity_handler_reference.unit.nil?
              - detail = output.quantity_value.round(2).l(precision: 0)
              - detail << " " + output.quantity_handler_reference.unit.symbol
            = add_detail_to_modal_block(title, detail, {icon: 'picto-matter'})


    - if intervention.tools.any?
      .block
        %h3.block-title= :equipments.tl

        - intervention.tools.each do |tool|
          - title = tool.product.name
          - detail = tool.product.nature.name
          = add_detail_to_modal_block(title, detail, tool, {icon: "picto-tractor", natures: [:travel, :intervention]})

    - if intervention.receptions.any?
      .block
        %h3.block-title= :service_deliveries.tl
        - intervention.receptions.each do |reception|
          - title = reception.sender.name
          - detail = ''
          = add_detail_to_modal_block(title, detail, { icon: 'picto-recent-actors' })



.modal-footer
  - displayed_state = intervention.state.tl
  - displayed_state = intervention.nature.l if intervention.nature.to_sym == :request

  - if next_state.present?
    = dropdown_menu_button(displayed_state, class: "btn btn-primary change-status dropup", icon: false, force_menu: true, disable_with: tl(:please_wait)) do |menu|
      - menu.item(next_state[0], change_state_backend_interventions_path(:intervention => { :interventions_ids => ([intervention.id]).to_json, state: next_state[1].to_sym, redirect: false }), method: :post) if next_state

  = link_to :see_details.tl, backend_intervention_path(intervention), class: 'btn btn-default'
  = link_to :edit.tl, edit_backend_intervention_path(intervention), class: 'btn btn-default'
